<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增项目配置')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-0" aria-expanded="true">小程序设置</a></li>
                    <li class=""><a data-toggle="tab" href="#tab-1" aria-expanded="true">商户设置</a></li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="true">文件上传设置</a></li>
                    <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="true">短信签名设置</a></li>
                </ul>
                <form  id="form-test-add">
                    <div class="tab-content">
                        <div id="tab-0" class="tab-pane active">
                            <div class="panel-body">
                                <div  style=" margin-top: 20px; ">
                                    <div class="form-horizontal"  th:each="config : ${list}">
                                        <div th:if="${config.type==0}" class="form-group">
                                            <input type="hidden" class="inputNum" th:value="${config.id}"/>
                                            <label class="col-sm-2 control-label" th:text="${config.name}+'：'"></label>
                                            <div class="col-sm-8">
                                                <input  class="form-control value" th:placeholder="'请输入'+${config.name}" th:name="${config.name}" th:value="${config.value}" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <div style="height: 150px;text-align: center;">
                                        <div class="col-sm-5">
                                            <a onclick="edits()" class="btn btn-success" style="margin: 0 5px;padding: 10px 30px;">
                                                保存
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="tab-1" class="tab-pane">
                            <div class="panel-body">
                                <div  style=" margin-top: 20px; ">
                                    <div class="form-horizontal"  th:each="config : ${list}">
                                        <div th:if="${config.type==1}" class="form-group">
                                            <input type="hidden" class="inputNum" th:value="${config.id}"/>
                                            <label class="col-sm-2 control-label" th:text="${config.name}+'：'"></label>
                                            <div class="col-sm-8">
                                                <input class="form-control value" th:placeholder="'请输入'+${config.name}" th:name="${config.value}" th:value="${config.value}" type="text" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <div style="height: 150px;text-align: center;">
                                        <div class="col-sm-5">
                                            <a onclick="edits()" class="btn btn-success" style="margin: 0 5px;padding: 10px 30px;">
                                                保存
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="tab-2" class="tab-pane">
                            <div class="panel-body">
                                <div  style=" margin-top: 20px; ">
                                    <div class="form-horizontal"  th:each="config : ${list}">
                                        <div th:if="${config.type==2}" class="form-group">
                                            <input type="hidden" class="inputNum" th:value="${config.id}"/>
                                            <label class="col-sm-2 control-label" th:text="${config.name}+'：'"></label>
                                            <div class="col-sm-8">
                                                <input class="form-control value" th:placeholder="'请输入'+${config.name}" th:name="${config.value}" th:value="${config.value}" type="text" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <div style="height: 150px;text-align: center;">
                                        <div class="col-sm-5">
                                            <a onclick="edits()" class="btn btn-success" style="margin: 0 5px;padding: 10px 30px;">
                                                保存
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="tab-3" class="tab-pane">
                            <div class="panel-body">
                                <div  style=" margin-top: 20px; ">
                                    <div class="form-horizontal"  th:each="config : ${list}">
                                        <div th:if="${config.type==3}" class="form-group">
                                            <input type="hidden" class="inputNum" th:value="${config.id}"/>
                                            <label class="col-sm-2 control-label" th:text="${config.name}+'：'"></label>
                                            <div class="col-sm-8">
                                                <input class="form-control value" th:placeholder="'请输入'+${config.name}" th:name="${config.value}" th:value="${config.value}" type="text" required>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <div style="height: 150px;text-align: center;">
                                        <div class="col-sm-5">
                                            <a onclick="edits()" class="btn btn-success" style="margin: 0 5px;padding: 10px 30px;">
                                                保存
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
    var prefix = ctx + "wechat/config"
    var code = true;
    var num = $(".inputNum").length;
    function edits() {
        $.modal.loading("正在处理中，请稍后...");
debugger
        $(".form-horizontal").each(function(){
            var id = jQuery(this).find("input").val();
            var value = jQuery(this).find(".value").val();
            if(id != undefined && value != undefined){
                $.ajax({
                    type : "post", //数据发送的方式（post 或者 get）
                    url :  prefix + "/edit",
                    data: { "id": id, "value": value},
                    cache : false,
                    async : true,
                    dataType : "TEXT",
                    success : function(data) {
                        num--;
                        var packJson = JSON.parse(data)
                        if(packJson.code!=0)
                            code = false;
                    },
                    error : function(msg) { //ajax请求失败后触发的方法
                        $.modal.msgError("请求错误");
                    }
                });
            }
            $.modal.closeLoading();
        });
        setTime();
    }

    function setTime() {
        setTimeout(function () {
            if(num!=0){
                setTime();
            }else{
                if(code){
                    $.modal.closeLoading();
                    $.modal.msgSuccess("修改成功");
                }
            }
        },500)
    }

    function getlogCode() {
        $.modal.loading("正在生成");
        var myID = new Date().getTime();
        $.getJSON(ctx+"/monitor/operlog/getCode?id="+myID, function(data){
            $.modal.closeLoading();
            $("#pic").remove();
            $("#code").append("<img id='pic' src='"+data.msg+"' width='80px'>")
            $.ajax({
                type : "post", //数据发送的方式（post 或者 get）
                url :  prefix + "/edit",
                data: { "id": '18', "value": myID},
                cache : false,
                async : true,
                dataType : "TEXT",
                success : function(data) {
                },
                error : function(msg) { //ajax请求失败后触发的方法
                    $.modal.msgError("请求错误");
                }
            });
        });
    }

</script>
</body>
</html>